package com.labichaoka.chaoka.ui.home.fragment.my.set;

import com.labichaoka.chaoka.entity.BaseResponse;
import com.labichaoka.chaoka.utils.SharedPreferencesManager;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by ruan on 2018/8/2.
 */

public class SettingPresenterImpl implements SettingPresenter, SettingInteractor.OnLogoutFinishedListener{
    private SettingView settingView;
    private SettingInteractor settingInteractor;

    public SettingPresenterImpl(SettingView view,SettingInteractor interactor){
        this.settingInteractor=interactor;
        this.settingView=view;
    }

    @Override
    public void init() {

    }

    @Override
    public void loginOut() {
        if (settingView!=null){
            settingView.showProgress();
        }
        settingInteractor.logout(this);
    }

    @Override
    public void onDestroy() {
        settingView=null;
    }

    @Override
    public void onLogoutSuccess(BaseResponse response) {
        settingView.hideProgress();
        SharedPreferencesManager.getInstance().clear();
        EventBus.getDefault().post(1);
        settingView.toLogin();

    }

    @Override
    public void onLogoutFailed() {
        settingView.hideProgress();
    }
}
